<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class PluginNav extends Model
{
    //
    protected $table = 'plugin_nav';

    protected $appends = ['children'];

    protected static $options = null;

    public function getChildrenAttribute(){
        $colls = $this->where('pid', $this->id)->get();
        return array_get(self::$options, 'with_children_hash') ?
            $colls->keyBy('id') : $colls;
    }

    public static function setOptions($options) {
        self::$options = $options;
        return parent::query();
    }
}
